package com.ccrfid.rmc6.repository.poi;

import com.ccrfid.rmc6.entity.poi.PoiLocationEntity;
import com.ccrfid.rmc6.repository.search.SearchableRepository;
import com.vividsolutions.jts.geom.Point;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;

import java.util.List;
import java.util.Set;

public interface PoiLocationRepository
        extends Repository<PoiLocationEntity, Long>, SearchableRepository<PoiLocationEntity> {
    //
    List<PoiLocationEntity> getAllBy();
    //
    List<PoiLocationEntity> getTop5ByLocationNameContainingOrderByLocationName(String locationName);
    //
    PoiLocationEntity getById(Long id);
    //
    PoiLocationEntity getTopByBindOrgId(Long bindOrgId);
    //
    PoiLocationEntity save(PoiLocationEntity entity);
    //
    void deleteById(Long id);
    void deleteByIdIn(List<Long> idList);
    //
    Boolean existsById(Long id);

    Boolean existsByLocationSn(String locationSn);

    Boolean existsByLocationSnAndIdNot(String locationSn, Long id);

    PoiLocationEntity getByLocationSn(String locationSn);

    List<PoiLocationEntity> getByBindOrgId(Long bindOrgId);

    @Query(value = "SELECT * FROM poi_location p WHERE p.map_level = 3 AND p.floor_number = ?1 " +
            "and st_contains(p.location_polygon, ?2) limit 1", nativeQuery = true)
    PoiLocationEntity get3LevelLocationContainsPoint(Integer floorNumber, Point point);
    //
    List<PoiLocationEntity> getAllByIdNotIn(Set<Long> idSet);
    //
    List<PoiLocationEntity> getAllByLocationType(Integer locationType);
    List<PoiLocationEntity> getAllByLocationTypeAndMapLevel(Integer locationType, Integer mapLevel);
    //
    List<PoiLocationEntity> getAllByLocationTypeAndIdNotIn(Integer locationType, Set<Long> idSet);

    List<PoiLocationEntity> getAllByLocationTypeNotIn(List<Integer> locationTypeList);

    List<PoiLocationEntity> getAllByLocationTypeNotInAndMapLevel(List<Integer> locationTypeList, Integer mapLevel);

    List<PoiLocationEntity> getAllByMapLevel(Integer mapLevel);

    PoiLocationEntity getByLocationName(String locationName);

    List<PoiLocationEntity> getAllByFloorNumberAndIdNotIn(Integer floorNumber, Set<Long> idSet);

    List<PoiLocationEntity> getAllByFloorNumber(Integer floorNumber);
}
